package com.cseg674.dataentry.javaparser;
import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.rdf.model.ModelFactory;

/**
 * The class that accesses the Ontology. Provides methods to retreive the ontology from the source 
 * and intialize the model, and access ontology classes and properties. 
 */
public class SourceOntology {
	 
	/**
	 * The source Model
	 */
	 private OntModel sourceOntModel;
	 /** 
	  * The path of where the onotology is stored
	  */
	 public final String ontologyURI;
	 
	 /**
	  * Default Constructor: pass an empty string ("") to use the default URI
	  */
	 public SourceOntology(String __ontologyURI)
	 {
		 // The Source Ontology File
		 ontologyURI = (__ontologyURI.length() > 0 ? __ontologyURI :        
		 				"http://cseg674.googlecode.com/svn/trunk/CSEG674/ontology/source.owl" );
	   
		 sourceOntModel = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM, null );
	 }
	 
	 /**
	  * Reads the Ontology file
	  * 
	  * @return	<code>true</code> if the octology was successfully read
	  */
	 public boolean Initialize()
	 {    
		 try {
			 sourceOntModel.read(ontologyURI);
		 }    
		 catch(Exception e)
		 {
			 System.err.print("Could not retrieve ontology from source: " + ontologyURI + "; reason: " +
			 e.getMessage() + "\n");
			 return false;
		 }
	    
		 return true;        
	  }
	     
	 /**
	  * Retrieves the RDF Class that represents classes, from the tree
	  * 
	  * @return		the class from the tree
	  */
	 public OntClass oClass()
	 {
	   OntClass t = sourceOntModel.getOntClass(ontologyURI + "#Class");
	   assert(t != null);
	   return(t);    
	 }
	 
	 /**
	  * Retrieves the RDF Property that represents derived from relationships, from the tree
	  * 
	  * @return		the derived from relationship from the tree
	  */
	 public OntProperty oHasDerives()
	 {
		 OntProperty t = sourceOntModel.getOntProperty(ontologyURI + "#derivesFrom");
		 assert(t != null);
		 return(t);
	 }
	 
	 /**
	  * Retrieves the RDF property that represents the implementes relationship, from the tree
	  * 
	  * @return		the inplementes relationship from the tree
	  */
	 public OntProperty oImplements()
	 {
		 OntProperty t = sourceOntModel.getOntProperty(ontologyURI + "#implements");
		 assert(t != null);
		 return(t);
	 }
	 
	 /**
	  * Retrieves the RDF Class that represents methods, from the tree
	  * 
	  * @return		the method from the tree
	  */
	 public OntClass oMethod()
	 {
	   OntClass t = sourceOntModel.getOntClass(ontologyURI + "#Method");
	   assert(t != null);
	   return(t);    
	 }
	 
	 /**
	  * Retrieves the RDF Property that represents calls relationships, from the tree
	  * 
	  * @return		the calls relationship from the tree
	  */
	 public OntProperty oCalls()
	 {
	   OntProperty t = sourceOntModel.getOntProperty(ontologyURI + "#calls");
	   assert(t != null);
	   return(t);
	 }
	 
	 /**
	  * Retrieves the RDF Property that represents modifies relationships, from the tree
	  * 
	  * @return		the modifies relationship from the tree
	  */
	 public OntProperty oModifies()
	 {
	   OntProperty t = sourceOntModel.getOntProperty(ontologyURI + "#modifiesMemeberVariable");
	   assert(t != null);
	   return(t);
	 }
	 
	 /**
	  * Retrieves the RDF Property that represents names, from the tree
	  * 
	  * @return		the name from the tree
	  */
	 public OntProperty oNamed()
	 {
	    OntProperty t = sourceOntModel.getOntProperty(ontologyURI + "#named");
	    assert(t != null);
	    return(t);
	 }
	 
	 /**
	  * Retrieves the RDF Property that represents types, from the tree
	  * 
	  * @return		the type from the tree
	  */
	 public OntProperty oType()
	 {
		 OntProperty t = sourceOntModel.getOntProperty(ontologyURI + "#hasType");
		 assert(t != null);
		 return(t);
	 }
	 
	 /**
	  * Retrieves the RDF Property that represents modifiers, from the tree
	  * 
	  * @return		the modifier from the tree
	  */
	 public OntProperty oModifier()
	 {
		 OntProperty t = sourceOntModel.getOntProperty(ontologyURI + "#hasModifier");
		 assert(t != null);
		 return(t);
	 }
	 
	 /**
	  * Retrieves the RDF Property that represents has method relationships, from the tree
	  * 
	  * @return		the has method relationship from the tree
	  */
	 public OntProperty oHasMethod() {
		 OntProperty t = sourceOntModel.getOntProperty(ontologyURI + "#hasMethod");
		 assert(t!=null);
		 return(t);
	 }
	 
	 /**
	  * Retrieves the RDF Class that represents Parameters, from the tree
	  * 
	  * @return		the parameter from the tree
	  */
	 public OntClass oParameter() {
		 OntClass t = sourceOntModel.getOntClass(ontologyURI + "#MemberVariable");
		 assert(t!=null);
		 return(t);
	 }
	 
	 /**
	  * Retrieves the RDF Property that represents has parameter relationships, from the tree
	  * 
	  * @return		the has parameter relationship from the tree
	  */
	 public OntProperty oHasParameter() {
		 OntProperty t = sourceOntModel.getOntProperty(ontologyURI + "#hasMemberVariable");
		 assert(t!=null);
		 return(t);
	 }
	 
	 /**
	  * Retrieves the RDF Class that represents member variabls, from the tree
	  * 
	  * @return		the member variable from the tree
	  */
	 public OntClass oField() {
		 OntClass t = sourceOntModel.getOntClass(ontologyURI + "#MemberVariable");
		 assert(t!=null);
		 return(t);
	 }
	 
	 /**
	  * Retrieves the RDF Property that represents has field relationships, from the tree
	  * 
	  * @return		the has field relationship from the tree
	  */
	 public OntProperty oHasField() {
		 OntProperty t = sourceOntModel.getOntProperty(ontologyURI + "#hasMemberVariable");
		 assert(t!=null);
		 return(t);
	 }
}
